package com.learn.practice.security;

import com.learn.practice.pojo.LoginUser;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserDetailServiceImpl implements BaseUserDetailsService {
    @Override
    public LoginUser loadUserByPhone(String phone) throws UsernameNotFoundException {
        return null;
    }

    @Override
    public LoginUser loadUserByUsername(String username) throws UsernameNotFoundException {
        if(!username.equals("user")){
            return new LoginUser("","");
        }

        List<GrantedAuthority> authorities = new ArrayList<>();
        SimpleGrantedAuthority simpleGrantedAuthority = new SimpleGrantedAuthority("user/admin");
        authorities.add(simpleGrantedAuthority);

        return new LoginUser("user","$2a$12$pgFnH5Ot.XIvbaTM7X9nNe8AGwBV.3eggszusKShXXG2HJ1fFdNMO", authorities);
    }
}
